package com.monolithiot.huawei.vo;

import com.alibaba.fastjson.annotation.JSONField;
import lombok.Data;

import java.util.Date;

/**
 * 2019/1/10 Create by 郭文梁
 * TokenResponseBody
 * 获取Token时响应数据JSON
 *
 * @author 郭文梁
 * @date 2019/1/10
 */
@Data
public class TokenResponseBody {
    private String scope;
    @JSONField(name = "token_type")
    private String tokenType;
    @JSONField(name = "expires_in")
    private Integer expiresIn;
    @JSONField(name = "access_token")
    private String accessToken;
    private Date createTime;

    /**
     * 判断当前Token是否过期
     *
     * @return true:过期  false:未过期
     */
    public boolean isOverdue() {
        if (expiresIn == null) {
            return true;
        }
        return ((System.currentTimeMillis() / 1000) - expiresIn) > (createTime.getTime() / 1000);
    }
}
